<?php
/**
* @software         [JiJinCMS]
* @author           [上海集锦信息科技有限公司]
* @website          [http://www.jijinweb.com]
* @email            [sunny@jijinweb.com]
**/
namespace app\admin\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
class UserLog extends \app\admin\controller\Admin{
    public function __construct(\think\App $app) {
        parent::__construct($app);
        $this->model=new \app\admin\model\UserLogModel();
        View::assign("typeInc",array(
            "add"=>"增加",
            "update"=>"编辑",
            "delete"=>"删除",
            "recovery"=>"恢复",
            "cancelChecked"=>"取消审核",
            "unChecked"=>"审核不通过",
            "checked"=>"审核通过",
            "other"=>"其它",
        ));        
    }    
    //
    public function index(){		
        //搜索
        $where=array();
        $start_time = Request::param("start_time");
        $end_time = Request::param("end_time");
        if($start_time || $end_time){
            $start_time = strtotime($start_time ? $start_time : 0);
            $end_time = strtotime(($end_time ? $end_time : date("Y-m-d"))."23:59:59");
            $where[]=["addtime","between",[$start_time,$end_time]];
        }
        $username=Request::param("username");
        if($username){
            $where[]  = array('username','LIKE','%'.$username.'%');
        } 
        $ip = Request::param("ip");
        if($ip){
            $where[]  = ["ip",'LIKE','%'.$ip.'%'];
        }   
        $type=Request::param("type");
        if($type){
            $where[]  = ["type","=",$type];
        }         
        $table_name=Request::param("table_name");
        if($table_name){
            $where[]  = array('table_name','LIKE','%'.$table_name.'%');
        } 
        $primary_key=Request::param("primary_key");
        if($primary_key){
            $where[]  = array('primary_key','LIKE','%'.$primary_key.'%');
        } 
        $username=Request::param("username");
        if($username){
            $where[]  = array('username','LIKE','%'.$username.'%');
        } 
        $userid=Request::param("userid");
        if($userid){
            $where[]  = ["userid","=",$userid];
        }         
        //     
        $listRows=Request::param("listRow")?Request::param("listRow"):config("app.page_show_line");//每页显示多少条
        $data=$this->model::where($where)->order("addtime desc")->paginate(['list_rows'=>$listRows,'query' => request()->param()]);
        // 获取分页显示
        $pagelist = $data->render();
        //
        View::assign("data",$data);
        View::assign("pagelist",$pagelist);
        return View::fetch();
    }  
    public function detail($id){
        $r=$this->model->find($id);
        View::assign("r",$r);
        return View::fetch();
    }
    //清空指定时间以前的日志
    public function clearLog(){
        $where[]=array("addtime","<",(time()-(3600*24*180)));
        $this->model->where($where)->delete();
        //记录日志
        $this->UserLogModel->add(Request()->action(),$this->model->getName(),0,"清除半年以前的操作日志");            
        $this->success();
    }
}
